
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';

import 'custom_monodrag.dart';

class CustomDirectionPanDetector extends StatelessWidget {
  final GestureDragDownCallback? onPanDown;

  /// A pointer has contacted the screen with a primary button and has begun to
  /// move.
  ///
  /// See also:
  ///
  ///  * [kPrimaryButton], the button this callback responds to.
  final GestureDragStartCallback? onPanStart;

  /// A pointer that is in contact with the screen with a primary button and
  /// moving has moved again.
  ///
  /// See also:
  ///
  ///  * [kPrimaryButton], the button this callback responds to.
  final GestureDragUpdateCallback? onPanUpdate;

  /// A pointer that was previously in contact with the screen with a primary
  /// button and moving is no longer in contact with the screen and was moving
  /// at a specific velocity when it stopped contacting the screen.
  ///
  /// See also:
  ///
  ///  * [kPrimaryButton], the button this callback responds to.
  final GestureDragEndCallback? onPanEnd;

  /// The pointer that previously triggered [onPanDown] did not complete.
  ///
  /// See also:
  ///
  ///  * [kPrimaryButton], the button this callback responds to.
  final GestureDragCancelCallback? onPanCancel;

  final Widget? child;
  
  final AxisDirection axisDirection;
  final HitTestBehavior behavior;

  const CustomDirectionPanDetector({super.key,  this.child, this.onPanDown, this.onPanStart, this.onPanUpdate, this.onPanEnd, this.onPanCancel, required this.axisDirection, required this.behavior });

  @override
  Widget build(BuildContext context) {
    return RawGestureDetector(
        behavior: behavior,
        gestures: <Type, GestureRecognizerFactory>{
          CustomPanGestureRecognizer: GestureRecognizerFactoryWithHandlers<CustomPanGestureRecognizer>(
                  () => CustomPanGestureRecognizer(axisDirection: axisDirection),
                  (CustomPanGestureRecognizer instance) {
                    instance
                      ..onDown = onPanDown
                      ..onStart = onPanStart
                      ..onUpdate = onPanUpdate
                      ..onEnd = onPanEnd
                      ..onCancel = onPanCancel;
                  }
          )
        },
        child: child
    );
  }
}